home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / NNUTL101.ZIP / NNTEST2 / NNTEST2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-13  |  3.9 KB  |  77 lines

  1. /*--------------------------------------------------------------------------*
  2.  * Gregory Stevens                                                   7/1/93 *
  3.  *                               NNTEST2.C                                  *
  4.  *                                                                          *
  5.  *   This is a test file to test the nn*.c series with back-propagation.    *
  6.  * for this file, the following parameters in the following files should be *
  7.  * set:                                                                     *
  8.  *      NNPARAMS.C : INPUT_LAYER_SIZE   1                                   *
  9.  *                   OUTPUT_LAYER_SIZE  1                                   *
  10.  *                   NUM_HIDDEN_LAYERS  0                                   *
  11.  *                                                                          *
  12.  *      NNINPUTS.C : NUM_PATTERNS  10                                       *
  13.  *                                                                          *
  14.  *      NNSTRUCT.C : InitNet()  ...should set output nodes as logistic...   *
  15.  *                                                                          *
  16.  *      NNBKPROP.C : EPSILON 0.25  (recommended...this is what I used)      *
  17.  *                                                                          *
  18.  *  Everything else can be left unchanged.  The input files should each     *
  19.  * consist of five real numbers, where they are in matching order of input  *
  20.  * and desired output.  The output of this file simply lists the input,     *
  21.  * weight, output, threshhold, desired output.  It pauses at each training  *
  22.  * epoch.                                                                   *
  23.  *                                                                          *
  24.  * NOTE: LOGISTIC UNITS TAKE _MUCH_ LONGER THAN LINEAR TO CONVERGE!!!!!!!   *
  25.  *--------------------------------------------------------------------------*/
  26. #include "nnbkprop.c"                /* to chain it to the nn*.c utilities  */
  27. #include <math.h>                    /* for the exp() for logistic units    */
  28.  
  29. #define NUM_ITS 2000                 /* iterations before it stops          */
  30.  
  31. /*  MAIN PROGRAM  */
  32. void main()
  33. {
  34.   int Pattern;                         /* for looping through patterns   */
  35.   int Layer;                           /* for looping through layers     */
  36.   int LCV;                             /* for looping training sets      */
  37.   NNETtype Net;
  38.   PATTERNtype InPatterns, OutPattern;
  39.  
  40.   Net = InitNet( NUMNODES );            /* initializes the network        */
  41.   InPatterns = InitInPatterns(0);       /* loads input patterns from file */
  42.   OutPattern = InitOutPatterns();       /* loads output patterns from file*/
  43.  
  44.   for (LCV=0; (LCV < NUM_ITS); ++LCV)   /* loop through a training set    */
  45.     {
  46.       for (Pattern=0; (Pattern<NUM_PATTERNS); ++Pattern)
  47.          {
  48.             /* FORWARD PROPAGATION */
  49.             Net = UpDateInputAct( InPatterns, Pattern, Net );
  50.             for (Layer=1; (Layer<NUMLAYERS); ++Layer)
  51.               {
  52.                  Net = UpDateLayerAct( Net, Layer );
  53.               }
  54.  
  55.             /* OUTPUT PRINTS */
  56.             if (LCV>1990)
  57.                {
  58.                   printf( "Input: %4.2f  ", Net.unit[0][0].state );
  59.                   printf( "Weight:%4.2f  ", Net.unit[1][0].weights[0]);
  60.                   printf( "Output:%4.2f  ", Net.unit[1][0].state  );
  61.                   printf( "Thresh:%4.2f  ", Net.unit[1][0].thresh );
  62.                   printf( "Goal: %4.2f\n",  OutPattern.p[Pattern][0] );
  63.                }
  64.  
  65.             /* BACKWARD PROPAGATION */
  66.             Net = UpDateWeightandThresh( Net, OutPattern, Pattern );
  67.          }
  68.  
  69.       if (LCV>1990)
  70.         {
  71.            getc(stdin);           /* pause inbetween training epochs */
  72.            printf( "\n" );        /* skip a line  */
  73.         }
  74.  
  75.     }
  76. }
  77.